package org.dromara.apartment.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.apartment.domain.vo.LabelInfoVo;
import org.dromara.apartment.domain.bo.LabelInfoBo;
import org.dromara.apartment.service.ILabelInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 标签信息
 * 前端访问路由地址为:/apartment/label
 *
 * @author CKJ
 * @date 2025-06-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/label")
public class LabelInfoController extends BaseController {

    private final ILabelInfoService labelInfoService;

    /**
     * 分页查询标签信息列表
     */
    @SaCheckPermission("apartment:label:list")
    @GetMapping("/list")
    public TableDataInfo<LabelInfoVo> list(LabelInfoBo bo, PageQuery pageQuery) {
        return labelInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询标签信息列表
     */
    @SaCheckPermission("apartment:label:list")
    @PostMapping("/getAllList")
    public R<List<LabelInfoVo>> getAllList(@RequestBody LabelInfoBo bo) {
        return R.ok(labelInfoService.queryList(bo));
    }

    /**
     * 获取标签信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("apartment:label:query")
    @GetMapping("/{id}")
    public R<LabelInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(labelInfoService.queryById(id));
    }

    /**
     * 新增标签信息
     */
    @SaCheckPermission("apartment:label:add")
    @Log(title = "标签信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LabelInfoBo bo) {
        return toAjax(labelInfoService.insertByBo(bo));
    }

    /**
     * 修改标签信息
     */
    @SaCheckPermission("apartment:label:edit")
    @Log(title = "标签信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LabelInfoBo bo) {
        return toAjax(labelInfoService.updateByBo(bo));
    }

    /**
     * 删除标签信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("apartment:label:remove")
    @Log(title = "标签信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(labelInfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
